<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>admin page</title>
	<link rel="stylesheet" href="css/bootstrap.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
	<div class="navbar navbar-fixed-top navbar-inverse">
		<div class="navbar-inner">
		<a class="brand" href="#">project</a>
		<ul class="nav">
		<li><a href="login-success.jsp">服务</a></li>
		<li class="active"><a href="tolist.jspx?father=0" >文件下载列表</a></li>
		<li>&nbsp;&nbsp;&nbsp;&nbsp;</li>
		<li>
			<form action="findmd.jspx"  id="form" method="post" class="navbar-search">
				<input type="text" name="fiel.md"  class="input-medium search-query" placeholder="MD5码......" required="required" id="md" onkeyup="sub(event)"/>
			</form>
		</li>
		<li><a href="exit.jspx">退出</a></li>
		</ul>
		</div>
	</div>
	<div style="margin-top:100px;">
	<h1>文件列表</h1>
	<a href="tolist.jspx?father=${fiel.father }">&gt;&gt;&gt;&gt;</a><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;<a href="#" id="showfile">创建文件夹</a>&gt;&gt;
	
	<form action="makedir.jspx" id="form2" method="post" style="width:380px;margin-left:50px;display:none;">
		文件名：<input type="text" name="name" id="name" onkeyup="subss(event)"/>
			<input type="hidden" name="father" value="${fiel.id }">
			<input type="hidden" name="userid" value="${user.id }">
			<input type="submit" value="提交" class="btn btn-success"onclick="subfilename()" />
	</form>
	
<table class="table" >
	<tr>
		<th>编号</th>
		<th>作者</th>
		<th>上传时间</th>
		<th>下载</th>
		<th>MD5</th>
		<th>大小</th>
		<th>操作</th>
	</tr>
		<c:forEach var="f" items="${list }" varStatus="status">
	<tr>
		<td>${status.count}</td>
		<td>${f.userid==user.id?"我的文件":""}</td>
		<td>${f.time }</td>
		<td>
			<c:if test="${f.son ==-1 or f.son ==-4}"><a href="tolistson.jspx?fileId=${f.id }&son=${f.son}">${f.name }<img src="img/folder.gif"/></a></c:if>
			<c:if test="${f.son ==-2}"><a href="download.jspx?fileId=${f.id }">${f.name }</a></c:if>
			<input type="text" name="name" style="display:none;" id="${f.id }" required="required" value="${f.name }"onkeyup="updatename(event,this)"/>
		</td>
		<td>${f.md }</td>
		<td><a href="#"  rel="tooltip" data-original-title="大小(B)" class="t" data-content="${f.length/1024/1024 }">${f.length }</a></td>
		<td><c:if test="${f.son !=-4}"><a href="#" onclick="del(${f.id})">删除</a>|</c:if><a href="#" onclick="update(${f.id})">修改</a></td>
	</tr>
	</c:forEach>
</table>
<script type="text/javascript">
	
</script>
<form action="upload.jspx"  method="post" enctype="multipart/form-data" style="width:380px;">
		<input type="hidden" name="father" value="${fiel.id }" />
		<input type="file" name="file" id="password" />
			<input type="submit" value="提交" class="btn btn-success" onclick="sub()" />
</form>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;
	<a href="#myModal" role="button" class="btn btn-success" data-toggle="modal">离线下载</a>&gt;&gt;<br>
 
		<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h3 id="myModalLabel">离线下载</h3>
			</div>
			<div class="modal-body">
			<form action="offlinedownload.jspx"  id="form1" method="post" >
						文件名：<label for="name">
										<input type="text" name="name" required="required" id="name"/>
									</label>
						有效文件地址:<label for="name">
												<input type="text " name="uri"  required="required" id="url" pattern="http://[a-zA-Z0-9\.\?:/=]{0,200}" onkeyup="subss(event)"/>
										</label>
						<input type="hidden" name="father" value="${fiel.id }">
							<input type="submit" value="提交" class="btn btn-success" onclick="subs()" />
							<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
					</form>
			</div>
			<div class="modal-footer">
			</div>
		</div>
	</div>
	<br>
	<br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;<a data-original-title="<p style='font-size:20px;color:#f89406;font-weight:bold;'>提示</p>" href="#" class="tt btn btn-success btn-large" rel="popover" data-content="<p style='color:#9d261d'>MD5相同的文件，文件内容相同，可以凭借MD5查找文件哦！</p>">放上鼠标查看</a>&gt;&gt;
	<script type="text/javascript">
		function sub(event){
			if(event.keycode==13){
				$("#form").submit();
			}
		};
		$("#showfile").click(function(){
				$("#form2").toggle();
			});
		function subss(event){
			if(event.keycode==13){
				subs();
			}
		};
		function subfilename(){
		$("form2").submit();
		};
		function del(id){
			$.post("delfiel.jspx", { id: id},
			   function(data){
				if(data=='ok'){
			     	window.location="tolist.jspx";
			     }else{
			     alert("error");
			     }
			   });
		}
		function update(id){
			$("#"+id).show();
		};
	function updatename(event,ob){
		if(event.keyCode==13){
		var id=ob.id;
		var name=ob.value;
			$.post("updatefiel.jspx", { id: id,name:name},
			   function(data){
			     if(data=='ok'){
			     	window.location="tolist.jspx";
			     }else{
			     alert("error")
			     }
			   })
		}
	};
	   $('.t').tooltip({'trigger':'hover','placement':'top'});
	   $('.tt').popover({'trigger':'hover','placement':'top'});
	</script>
</body>
</html>